package algorithm.recursionAndbacktrack.combination.p78;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> subs = new ArrayList<>();
        if (nums != null && nums.length > 0) {
            subsets(nums, 0, subs, new ArrayDeque<>());
        }
        return subs;
    }

    private void subsets(int[] nums, int startIndex, List<List<Integer>> subs, ArrayDeque<Integer> sub) {
        subs.add(new ArrayList<>(sub));
        if (nums.length == sub.size()) {
            return;
        }

        for (int i = startIndex; i < nums.length; i++) {
            sub.addLast(nums[i]);
            subsets(nums, i + 1, subs, sub);
            sub.removeLast();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().subsets(new int[]{1, 2, 3}));
    }
}